Framework
Interactable entities that can be held in inventories.
Items are objects that are contained inside of an Inventory, or as standalone entities if they are dropped in the world. They usually have functionality that provides more gameplay aspects to the schema.
For an item to have an actual presence, they need to be instanced (usually by spawning them). Items describe the
properties, while instances are a clone of these properties that can have their own unique data (e.g., an ID card will have the
same name but different numerical IDs). You can think of items as the class, while instances are objects of the Item
class.
Functions
itemMeta:__eq(other)
Returns true if this item is equal to another item. Internally, this checks item IDs.
Parameters
-
other
Item
The item to compare to.
Returns
-
Boolean
Whether or not this item is equal to the given item.
Example Usage
if lia.item.instances[1] == lia.item.instances[2] then
print("Items are equal.")
else
print("Items are not equal.")
end
itemMeta:__tostring()
Returns a string representation of this item.
Returns
-
String
String representation.
Example Usage
print(tostring(lia.item.instances[1]))
Output: "item[uniqueID][1]"
itemMeta:addQuantity(quantity, receivers, noCheckEntity)
Adds a specified quantity to the item's current quantity.
Parameters
-
quantity
Integer
The quantity to add.
-
receivers
Table
Players who should receive updates about the quantity change.
-
noCheckEntity
Boolean
If true, entity checks will be skipped.
Example Usage
item:addQuantity(5, {player1, player2}, false)
itemMeta:call(method, client, entity, ...)
Calls one of the item's methods.
Parameters
-
method
String
The method to be called.
-
client
Player
The player to pass when calling the method, if applicable.
-
entity
Entity
The entity to pass when calling the method, if applicable.
-
...
Table
Arguments to pass to the method.
Returns
-
any
The values returned by the method.
Example Usage
item:call("use", player, entity, arg1, arg2)
itemMeta:delete()
Deletes the item from the database and performs cleanup.
Returns
-
Deferred
A deferred object representing the asynchronous operation of deleting the item from the database.
Example Usage
item:delete():next(function()
print("Item deleted from database.")
end)
itemMeta:destroy()
Destroys the item instance, removing it from the game world and notifying all clients.
Example Usage
item:destroy()
itemMeta:getData(key, default)
Returns the value stored on a key within the item's data.
Parameters
-
key
String
The key in which the value is stored.
-
default
any[opt]
The value to return in case there is no value stored in the key.
Returns
-
any
The value stored within the key.
Example Usage
local health = item:getData("health", 100)
print("Item Health:", health)
itemMeta:getDesc()
Returns the description of the item.
Returns
-
String
The description of the item.
Example Usage
local desc = item:getDesc()
print("Description:", desc)
itemMeta:getDesc()
Returns the description of the item.
Returns
-
String
The description of the item.
Example Usage
local desc = item:getDesc()
print("Item Description:", desc)
itemMeta:getEntity()
Returns the item's entity.
Returns
-
Entity
The entity of the item.
Example Usage
local entity = item:getEntity()
if entity then
print("Item entity exists.")
end
itemMeta:getID()
Returns this item's database ID. This is guaranteed to be unique.
Returns
-
Integer
Unique ID of item.
Example Usage
local itemID = item:getID()
print("Item ID:", itemID)
itemMeta:getModel()
Returns the model of the item.
Returns
-
String
The model of the item.
Example Usage
local model = item:getModel()
print("Model:", model)
itemMeta:getName()
Returns the name of the item.
Returns
-
String
The name of the item.
Example Usage
local name = item:getName()
print("Item Name:", name)
itemMeta:getName()
Returns the name of the item.
Returns
-
String
The name of the item.
Example Usage
local name = item:getName()
print("Item Name:", name)
itemMeta:getOwner()
Returns the player that owns this item.
Returns
-
Player
Player owning this item.
Example Usage
local owner = item:getOwner()
if owner then
print("Item is owned by:", owner:Nick())
else
print("Item has no owner.")
end
itemMeta:getPrice()
Returns the price of the item.
Returns
-
Float
The price of the item.
Example Usage
local price = item:getPrice()
print("Price:", price)
itemMeta:getQuantity()
Returns the quantity of the item.
Returns
-
Integer
The quantity of the item.
Example Usage
local qty = item:getQuantity()
print("Quantity:", qty)
itemMeta:getSkin()
Returns the skin of the item.
Returns
-
Integer
The skin of the item.
Example Usage
local skin = item:getSkin()
print("Skin:", skin)
itemMeta:hook(name, func)
Changes the function called on specific events for the item.
Parameters
-
name
String
The name of the hook.
-
func
Function
The function to call once the event occurs.
Example Usage
item:hook("onUse", function(item)
print("Item was used.")
end)
itemMeta:interact(action, client, entity, data)
Performs an interaction action with the item.
Parameters
-
action
String
The interaction action to perform.
-
client
Player
The player performing the interaction.
-
entity
Entity
The entity associated with the interaction, if any.
-
data
Table
Additional data related to the interaction.
Returns
-
Boolean
Whether the interaction was successful.
Example Usage
if item:interact("use", player, entity, data) then
print("Interaction successful.")
else
print("Interaction failed.")
end
itemMeta:onDisposed()
Gets called upon destroying an item.
Example Usage
function ITEM:onDisposed()
print("Item has been disposed.")
end
itemMeta:onInstanced()
Gets called upon creating (instancing) an item.
Example Usage
function ITEM:onInstanced()
print("Item has been instanced.")
end
itemMeta:onRegistered()
Gets called when the item is registered.
Example Usage
function ITEM:onRegistered()
print("Item has been registered.")
end
itemMeta:onRemoved()
Gets called upon removing an item.
Example Usage
function ITEM:onRemoved()
print("Item has been removed.")
end
itemMeta:onRestored()
Gets called upon restoring an item.
Example Usage
function ITEM:onRestored()
print("Item has been restored.")
end
itemMeta:onSync()
Gets called upon syncing an item.
Example Usage
function ITEM:onSync(recipient)
print("Item has been synced with recipient:", recipient:Nick())
end
itemMeta:postHook(name, func)
Changes the function called after hooks for specific events for the item.
Parameters
-
name
String
The name of the hook.
-
func
Function
The function to call after the original hook was called.
Example Usage
item:postHook("onUse", function(item, result)
print("Item use post-processing.")
end)
itemMeta:print(detail)
A utility function which prints the item's details.
Parameters
-
detail
Boolean
Whether additional detail should be printed or not (Owner, X position, Y position).
Example Usage
item:print()
item:print(true)
itemMeta:printData()
A utility function printing the item's stored data.
Example Usage
item:printData()
itemMeta:remove(bNoReplication, bNoDelete)
Removes the item.
Parameters
-
bNoReplication
Boolean
Whether or not the item's removal should not be replicated.
-
bNoDelete
Boolean
Whether or not the item should not be fully deleted.
Returns
-
Deferred
A deferred object representing the asynchronous operation of removing the item.
Example Usage
item:remove():next(function()
print("Item removed.")
end)
itemMeta:removeFromInventory(preserveItem)
Removes the item from its current inventory.
Parameters
-
preserveItem
Boolean
If true, the item is not fully deleted from the database.
Returns
-
Deferred
A deferred object representing the asynchronous operation of removing the item.
Example Usage
item:removeFromInventory(true):next(function()
print("Item removed while preserving data.")
end)
itemMeta:setData(key, value, receivers, noSave, noCheckEntity)
Sets a key-value pair within the item's data table. This function updates the item's data and optionally synchronizes it with the entity's network variables and sends the updated data to specified receivers or the item's owner.
Parameters
-
key
String
The key to store the value under.
-
value
any[opt=nil]
The value to set for the key. If nil, the key is effectively removed.
-
receivers
Table
default: nil
A table of players to whom the data should be sent. Defaults to the item's owner.
-
noSave
Boolean
default: false
If true, prevents saving the data to the database.
-
noCheckEntity
Boolean
default: false
If true, skips updating the network variable for the item's entity.
Example Usage
item:setData("health", 100, {player1, player2}, false, false)
itemMeta:setQuantity(quantity, receivers, noCheckEntity)
Sets the quantity of the item to the specified value.
Parameters
-
quantity
Integer
The new quantity value.
-
receivers
Table
Players who should receive updates about the quantity change.
-
noCheckEntity
Boolean
If true, entity checks will be skipped.
Example Usage
item:setQuantity(10, {player1}, true)
itemMeta:spawn(position, angles)
Spawns an item entity based off the item table.
Parameters
-
position
Vector
The position in which the item's entity will be spawned.
-
angles
Angle
The angles at which the item's entity will spawn.
Returns
-
Entity
The spawned entity.
Example Usage
local spawnedEntity = item:spawn(Vector(0, 0, 0), Angle(0, 90, 0))
itemMeta:sync(recipient)
Synchronizes the item data with the specified recipient or broadcasts it to all clients if no recipient is specified.
Parameters
-
recipient
Player
optional
The player to whom the item data should be synchronized. If set to nil, the data is broadcasted to all clients.
Example Usage
item:sync(player)
item:sync()
itemMeta:transfer(newInventory, bBypass)
Transfers the item to another inventory.
Parameters
-
newInventory
Table
The inventory to which the item should be transferred.
-
bBypass
Boolean
Whether to bypass access checks for transferring the item.
Returns
-
Boolean
Whether the item was successfully transferred or not.
Example Usage
local success = item:transfer(targetInventory, true)
if success then
print("Item transferred successfully.")
else
print("Item transfer failed.")
end